package com.youxuan.config;

import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OssConfig {
    @Value("${oss.accessKey}")
    String accessKey;
    @Value("${oss.secretKey}")
    String secretKey;
    @Value("${oss.bucket}")
    String bucket;


    @Bean("upToken")
    public String getAuth() {
        return Auth.create(accessKey, secretKey).uploadToken(bucket);
    }

    //构造一个带指定 Region 对象的配置类
    com.qiniu.storage.Configuration cfg = new com.qiniu.storage.Configuration(Region.autoRegion());

    @Bean
    public UploadManager getUploadManager() {
        return new UploadManager(cfg);
    }
}
